export function timeDesc(time) {
  var date = new Date().getTime()
  // console.log(date)
  // 毫秒差
  var decTime = date - time
  // 天数差,向下取整
  var decDay = Math.floor(decTime / (1000 * 60 * 60 * 24))
  // console.log(decDay)
  var timeDate = new Date(time)
  if (decDay < 1) {
    // 今天 上午9.08
    var h = timeDate.getHours()
    var m = timeDate.getMinutes()
    h = h > 12 ? `下午${h - 12}` : `上午${h}`
    m = returnDoubleDate(m + '')
    return h + ':' + m
  } else if (decDay === 1) {
    // 昨天,时间有可能已经是前天了
    return '昨天'
  } else if (decDay > 1 && decDay <= 5) {
    // 星期几
    var week = timeDate.getDay()
    var weekArray = ['天', '一', '二', '三', '四', '五', '六']
    return `星期${weekArray[week]}`
  } else {
    // 月-日
    let M = returnDoubleDate(timeDate.getMonth() + 1 + '')
    let d = returnDoubleDate(timeDate.getDate() + '')
    return M + '-' + d
  }
}
function returnDoubleDate(time) {
  return ('00' + time).substr(time.length)
}
